home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 2.5 KB | 105 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // BCNodes.h
- //
- // This file contains the declaration of various node classes.
-
- #ifndef BCNODES_H
- #define BCNODES_H 1
-
- #include <stddef.h>
- #include "BCType.h"
-
- // Class denoting an Item/Value pair
-
- template<class Item, class Value>
- class BC_TPair {
- public:
-
- BC_TPair();
- BC_TPair(const Item& item)
- : fItem(item) {}
- BC_TPair(const Item& item, const Value& value)
- : fItem(item),
- fValue(value) {}
- BC_TPair(const BC_TPair<Item, Value>& a)
- : fItem(a.fItem),
- fValue(a.fValue) {}
-
- BC_TPair<Item, Value>& operator=(const BC_TPair<Item, Value>& a)
- {fItem = a.fItem;
- fValue = a.fValue;
- return *this;}
- BC_Boolean operator==(const BC_TPair<Item, Value>& a) const
- {return (fItem == a.fItem);}
- BC_Boolean operator!=(const BC_TPair<Item, Value>& a) const
- {return !operator==(a);}
-
- Item fItem;
- Value fValue;
-
- };
-
- // Class denoting a simple node consisting of an item and pointers to
- // the previous and next Items
-
- template<class Item, class StorageManager>
- class BC_TNode {
- public:
-
- BC_TNode(const Item& i,
- BC_TNode<Item, StorageManager>* previous,
- BC_TNode<Item, StorageManager>* next)
- : fItem(i),
- fPrevious(previous),
- fNext(next)
- {if (previous)
- previous->fNext = this;
- if (next)
- fNext->fPrevious = this;}
-
- Item fItem;
- BC_TNode<Item, StorageManager>* fPrevious;
- BC_TNode<Item, StorageManager>* fNext;
-
- static void* operator new(size_t);
- static void operator delete(void*, size_t);
-
- };
-
- // Class denoting a simple node consisting of an item, a pointer to
- // the parent, pointers to the left and right items, and a reference count
-
- template<class Item, class StorageManager>
- class BC_TBinaryNode {
- public:
-
- BC_TBinaryNode(const Item& i,
- BC_TBinaryNode<Item, StorageManager>* parent,
- BC_TBinaryNode<Item, StorageManager>* left,
- BC_TBinaryNode<Item, StorageManager>* right)
- : fItem(i),
- fParent(parent),
- fLeft(left),
- fRight(right),
- fCount(1)
- {if (left)
- fLeft->fParent = this;
- if (right)
- fRight->fParent = this;}
- ~BC_TBinaryNode();
-
- Item fItem;
- BC_TBinaryNode<Item, StorageManager>* fParent;
- BC_TBinaryNode<Item, StorageManager>* fLeft;
- BC_TBinaryNode<Item, StorageManager>* fRight;
- BC_Index fCount;
-
- static void* operator new(size_t);
- static void operator delete(void*, size_t);
-
- };
-
- #endif
-